<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>

</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="row">
                            <div class="col-sm-12" id="filmtypecontent">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-2">
                                <select class="form-control" id="input_state">
                                    <option value="-1">--状态--</option>
                                    <option value="0">上线</option>
                                    <option value="1">下线</option>

                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control" id="input_year">
                                    <option value="-1">--年份--</option>
                                    <option value="2017">2017</option>
                                    <option value="2016">2016</option>
                                    <option value="2015">2015</option>
                                    <option value="2014">2014</option>
                                    <option value="2013">2013</option>
                                    <option value="2012">2012</option>
                                    <option value="2011">2011</option>
                                    <option value="2010">更早</option>
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control" id="input_country">

                                </select>
                            </div>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="input_name"
                                       placeholder="名称...">
                            </div>

                            <div class="col-sm-2">
                                <select class="form-control" id="film_price" name="film_price">

                                </select>
                            </div>
                            <div class="col-sm-1 pull-right">
                                <button class="btn btn-block btn-default " id ="btn_search" onclick="searchFilmList()">查询
                                </button>
                            </div>
                        </div><!-- /.box-header -->
                        <div class="row">
                            <div class="col-sm-6">
                            </div>
                            <div class="col-sm-3">
                                <a class="btn btn-block btn-success" href="/page/video/qiniufileup" target="_blank">+
                                    上传电影</a>
                            </div>
                            <div class="col-sm-3">
                                <a class="btn btn-block btn-success" href="/page/video/filmadd">+
                                    添加电影</a>
                            </div>
                        </div>
                    </div>

                    <div class="box-body table-responsive no-padding">
                        <table class="table table-bordered table-striped dataTable">
                            <tbody>
                            <thead>
                            <tr>
                                <th>封面</th>
                                <th>名称</th>
                                <th>类型</th>
                                <th>年份</th>
                                <th>国家</th>
                                <th>导演</th>
                                <th>演员</th>
                                <th>价格</th>
                                <th>评分</th>
                                <th>状态</th>
                                <th>添加时间</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                            </thead>
                            <tbody id="bodycontent">


                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                    <div id="pagecontent" class="pagination"></div>
                </div><!-- /.box -->
            </div>
        </div>
    </section>

</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <!--layoutmain footer...-->
    <!--<br />-->
    <script src="/js/jquery/jquery.form.js"></script>
    <script src="/js/mortise/contrydata.js"></script>


    <script type="text/javascript">

        FillPricetagSelect('film_price');
        fillCountrySelect('input_country');
        fillDivVideoType('filmtypecontent','');

        var film_data = {};

        function searchFilmList() {
            var filmtypeidlist='';
            $.each($('input[id^=input_check]'),function (index,item) {
                if (item.checked==true){
                    filmtypeidlist+='1';
                }
                else{
                    filmtypeidlist+='0';
                }
            });
            if (filmtypeidlist.indexOf('1')==-1){
                filmtypeidlist=''
            }
            film_data = {
                state:$('#input_state').val(),
                years:$('#input_year').val(),
                country:$('#input_country').val(),
                filmtype:filmtypeidlist,
                name:$('#input_name').val(),
                filmprice:$('#film_price').val(),
                pno: 1,
                pagesize: 10,
                allcount:-1
            };
            LoadFilmList();
        }
        //加载列表
        searchFilmList();
        function LoadFilmList() {
            $('#pagecontent').html('');
            $.ajax({
                    url: '/api/video/getfilmlist',
                    data: film_data,
                    dataType: 'json',
                    success: function (data) {
                        if (mortise_layout.ValidataResult(data)) {
                            if (data.result) {
                                film_data.allcount = data.result.count;
                                var html = '';
                                $.each(data.result.list, function (index, item) {
                                    html += getHtml(item);
                                })
                                $('#bodycontent').html(html);
                                ShowPage('pagecontent', film_data, function (pno) {
                                    film_data.pno = pno;
                                    LoadFilmList();
                                });
                            }
                            else {
                                alert('返回数据错误！');
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }

        function  getHtml(dataObject) {
            var countryObject=getCountryObj(dataObject.fCountry);

            var countryName='';
            if (countryObject){
                countryName=countryObject.name;
            }
            else{
                countryName='未知';
            }

            var stateHtml='';
            if (dataObject.fShow==0){
                stateHtml= '<span class="label label-danger">上线</span>'
            }
            else if (dataObject.fShow=='1'){

                stateHtml= '<span class="label label-success">下线</span>'
            }
            return ' <tr>'+
                '<td><img style="width: 40px;height: 40px;" src="'+dataObject.fPhoto+'"></td>'+
                '<td>'+dataObject.fName+'</td>'+
                '<td>'+GetVideoTypeNameList(dataObject.fFilmtype)+'</td>'+
                '<td>'+dataObject.fYear+'</td>'+
                '<td>'+countryName+'</td>'+
                '<td>'+dataObject.fDirector+'</td>'+
                '<td>'+dataObject.fPerformer+'</td>'+
                '<td>'+dataObject.fPricetagname+'</td>'+
                '<td><span class="badge bg-light-blue">'+dataObject.fScore+'</span></td>'+
                '<td>'+stateHtml+'</td>'+
                '<td>'+dataObject.fIntime+'</td>'+
                '<td>' +
                '<a style="cursor: pointer" href="/page/video/filmupdate?fid='+dataObject.fId+'">修改</a>&nbsp;&nbsp;' +
                '' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateFilm(\''+dataObject.fId+'\',0)">上线</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateFilm(\''+dataObject.fId+'\',1)">下线</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="AddHistory(\''+dataObject.fId+'\')">添加历史的今天</a>&nbsp;&nbsp;'+
                '<a style="cursor: pointer" href="#" onclick="AddTopLog(\''+dataObject.fId+'\',1)">电影置顶</a>&nbsp;&nbsp;'+
                '<a style="cursor: pointer" href="#" onclick="AddToday(\''+dataObject.fId+'\',1)">今日推荐</a></td>'+
                '</tr>';
        }
        function UpdateSateFilm(uid,state) {
            $.ajax({
                    url: '/api/video/updatefilmstate',
                    data: {id: uid,state:state},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadFilmList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
        function AddHistory(fid) {
            var html =' <form id="historyform" class="form-horizontal" method="post"'+
                'enctype="multipart/form-data">'+
                '<div             class="form-horizontal">' +
                '<div class="box-body" style="min-width: 480px;">' +
                ' <input type="hidden" name="history_objectid" id="history_objectid" value="' + fid
                + '">' +
                ' <input type="hidden" name="history_classtype" id="history_classtype" value="1">' +
                ' ' +
                ' <div class="form-group">' +
                ' <label for="func_name" class="col-sm-3 control-label">日期</label>' +
                ' <div class="col-sm-9">' +
                ' <input type="text" class="form-control" ' +
                'id="history_date" placeholder="日期"  name="history_date">' +
                ' </div>' +
                '  </div>' +
                '<div class="form-group">' +
                '<label for="history_keyword" class="col-sm-3 control-label">' +
                '   历史事件</label>' +
                '   <div class="col-sm-9">' +
                '   <textarea class="form-control" name="history_keyword" rows="3" placeholder="历史事件 ..."' +
                ' id="history_keyword"></textarea>' +
                '  </div>' +
                '   </div>' +
                ' <div class="box-footer">' +
                '</div>' +
                '</div></form>';
            dialog({
                title: '添加历史的今天',
                content: html,
                cancel: true,
                okValue:'确定',
                ok:function () {
                    var options = {
                        url: '/api/histroy/add',
                        type:'post',
                        success: function (data) {
                            if (data) {
                                if (data.code=='OperateOk') {
                                    dialog({
                                        title: '提示',
                                        content: '操作成功！',
                                        cancel: false,
                                        ok: function () {
                                        }
                                    }).width(320).showModal();
                                    LoadFuncList();
                                }
                                else if (data.code='FiledRepeat'){
                                    dialog({
                                        title: '提示',
                                        content: '您已添加此电影，不能重复添加！',
                                        cancel: false,
                                        ok: function () {
                                        }
                                    }).width(320).showModal();
                                    LoadFuncList();
                                }
                                else {
                                    dialog({
                                        title: '提示',
                                        content: '操作失败！',
                                        cancel: false,
                                        ok: function () {
                                        }
                                    }).width(320).showModal();
                                }
                            }
                        }
                    };
                    $("#historyform").ajaxSubmit(options);
                }
            }).showModal().width(500).height(200);
        }


        function AddTopLog(uid) {
            $.ajax({
                    url: '/api/video/addTopLog',
                    data: {objectid: uid,classtype:1},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '置顶成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '置顶失败，电影已置顶！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }



        function AddToday(uid) {
            $.ajax({
                    url: '/api/video/addToday',
                    data: {objectid: uid,classtype:1},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '添加成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '添加失败，电影已存在！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>